package com.company.sendemo.basics.ayJavaEight.stream;

import java.io.File;

public class mkdirs {
    public static void main(String[] args) {
        //新建目录
        mkdirs();
        //读取目录
        readdirs();
        //删除目录或文件
        File file = new File("D:/project/test3.txt");
//        delete(file);
    }
    public static void mkdirs(){
        String dirname="D:/project/test3.txt";
        File file = new File(dirname);
        //现在创建目录
        file.mkdirs();
    }
    public static void readdirs(){
        String dirname="D:/project";
        File f1 = new File(dirname);
        if (f1.isDirectory()){
            System.out.println("目录"+dirname);
            String s[] = f1.list();
            for (int i = 0; i < s.length; i++) {
                File f = new File(dirname + "/" + s[i]);
                if (f.isDirectory()){
                    System.out.println(s[i]+"是一个目录");
                }else {
                    System.out.println(s[i]+"是一个文件");
                }
            }
        }else {
            System.out.println(dirname+"不是一个目录");
        }
    }
    public static void delete(File file){
        File[] files = file.listFiles();
        if (files != null){
            for(File f: files){
                if (f.isDirectory()){
                    delete(f);
                }else {
                    f.delete();
                }
            }
        }
        file.delete();
    }
}
